#!/bin/bash
#leao:Fri Aug 23 10:18:00 AM CST 2024
checkmode(){
    path=$1
    filenames=$(ls -a "$path")  # 使用$(...)替代`...`以获得更好的兼容性

    for val in $filenames; do
        if [ "$val" != '.' ] && [ "$val" != '..' ]; then
            fullpath="$path/$val"  # 构建完整路径
            if [ -d "$fullpath" ]; then
                checkmode "$fullpath"  # 递归调用
            else
                modeVal=$(ls -l "$fullpath" | grep "rwx")  # 去掉多余的空格
                echo "$modeVal"
                if [ -z "$modeVal" ]; then
                    chmod 777 "$fullpath"  # 添加双引号以避免路径中有空格的问题
                    echo "ok"
                fi
            fi
        fi
    done
}

path=\$1
checkmode "$path"

